//
//  HomeInfoTCell.m
//  GuShiNews
//
//  Created by huachun on 2019/8/22.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "HomeInfoTCell.h"
#import "UserJubuViewModel.h"
#import "LunCommentModel.h"
#import "CenterAction.h"
#import "HomeIMGView.h"
#import "XLPhotoBrowser.h"

@interface HomeInfoTCell ()

@property (nonatomic, strong) UIImageView *User_logo;
@property (nonatomic, strong) UILabel *User_name;

@property (nonatomic, strong) UILabel *Label_bottom;

@property (nonatomic, strong) UILabel *Label_count;

@property (nonatomic, strong) CALayer *News_line;

@property (nonatomic, strong) UIButton *Usergoto;


@property (nonatomic, strong) HomeIMGView *Img_view;

@end

@implementation HomeInfoTCell

+ (instancetype)cellForTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"HomeInfoTCell";
    HomeInfoTCell  *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell){
        cell=[[HomeInfoTCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.backgroundColor=[UIColor whiteColor];
        tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
//        [cell setSelectionStyle:UITableViewCellSelectionStyleDefault];

        [cell.contentView addSubview:cell.User_logo];
        [cell.contentView addSubview:cell.User_name];
        [cell.contentView addSubview:cell.Usergoto];
        [cell.contentView addSubview:cell.Morebutton];
        [cell.contentView addSubview:cell.Label_showtype];
        [cell.contentView addSubview:cell.Label_bottom];
        [cell.contentView addSubview:cell.Label_count];
        [cell.contentView.layer addSublayer:cell.News_line];
        [cell.contentView addSubview:cell.Img_view];
    }
    
    return cell;
}

- (void)setModel:(LunCommentModel *)Model{
    if (_Model!=Model) {
        _Model = Model;
    }
    
    [_User_logo sd_setImageWithURL:[NSURL URLWithString:_Model.logo] placeholderImage:[UIImage imageNamed:@"user_logo.png"]];
    _User_name.text=_Model.name;
    _Label_bottom.frame = CGRectMake(15, 65, RECRWITCH-30, _Model.Height);
    _Label_bottom.text=_Model.lcomment_info;
    
    _Label_count.frame = CGRectMake(15, 65 + _Model.Height, RECRWITCH-30, 30);
    _Label_showtype.frame = CGRectMake(RECRWITCH-55, 65 + _Model.Height, 40, 30);
    
    if (_Model.type==0) {
        _Morebutton.hidden=YES;
        _Label_showtype.hidden = YES;
        _Label_count.text=[JonesClass timeZhuan:_Model.lcomment_date];
        
        _User_logo.frame=CGRectMake(15, 10, 45, 45);
        _User_logo.layer.cornerRadius  = 22.5;
        _User_logo.layer.borderWidth = 1.0;
        _User_name.frame = CGRectMake(70, 10, RECRWITCH/2-20, 45);
        
        _News_line.frame=CGRectMake(0, 65 + _Model.Height + 34, RECRWITCH, 10);
        
        
        if (_Model.Img_array>0) {
            _Img_view.hidden = NO;
            _Img_view.frame=CGRectMake(0, 65 + _Model.Height - (RECRWITCH-40)/3 - 5, RECRWITCH, (RECRWITCH-40)/3);
            [_Img_view setArray:_Model.Img_array];
            _Label_bottom.frame = CGRectMake(15, 65, RECRWITCH-30, _Model.Height - (RECRWITCH-40)/3-5);
        }else{
            _Label_bottom.frame = CGRectMake(15, 65, RECRWITCH-30, _Model.Height);
            _Img_view.hidden = YES;
        }
    }else{
        _Img_view.hidden = YES;
        _Morebutton.hidden=NO;
        _Label_showtype.hidden = NO;
        _Label_count.text=[JonesClass timeZhuan:_Model.lcomment_date];
        
        _User_logo.frame=CGRectMake(15, 15, 40, 40);
        _User_logo.layer.cornerRadius  = 20;
        _User_logo.layer.borderWidth = 0.0;
        _User_name.frame = CGRectMake(65, 15, RECRWITCH/2-20, 40);
        
        _News_line.frame=CGRectMake(0, 65 + _Model.Height + 34, RECRWITCH, 1);
    }
}

-(HomeIMGView *)Img_view{
    if (!_Img_view) {
        __weak typeof (self) weakSelf = self;
        _Img_view=[[HomeIMGView alloc] initWithFrame:CGRectMake(0, 185, RECRWITCH, (RECRWITCH-40)/3)];
        _Img_view.selectimg = ^(NSInteger Type) {
            [weakSelf show_img:Type];
        };
    }
    return _Img_view;
}

-(void)show_img:(NSInteger)no_type{
    XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:_Model.Img_array currentImageIndex:no_type];
    browser.seletBlock = ^(BOOL tui_ok) {
        
    };
}

- (UIButton *)Usergoto{
    if (!_Usergoto) {
        _Usergoto = [[UIButton alloc] initWithFrame:CGRectMake(15, 5, 55, 55)];
        [_Usergoto addTarget:self action:@selector(gotousercenter:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _Usergoto;
}

-(UIImageView *)User_logo{
    if (!_User_logo) {
        _User_logo                     = [[UIImageView alloc] init];
        _User_logo.layer.masksToBounds = YES;
        _User_logo.layer.cornerRadius  = 20;
        _User_logo.contentMode         = UIViewContentModeScaleAspectFill;
        _User_logo.backgroundColor = backColor;
        _User_logo.layer.borderColor = NavItemTitleColor.CGColor;
        _User_logo.frame=CGRectMake(15, 15, 40, 40);
        [_User_logo sd_setImageWithURL:[NSURL URLWithString:@"https://pics7.baidu.com/feed/94cad1c8a786c917ea4cc8a9ec9722ca3ac75706.jpeg?token=d7b89c9f3591aa91417d4a336aef0aed&s=A5B85795D0607D03185F59D9030070BF"]];
    }
    return _User_logo;
}

-(UILabel *)User_name{
    if (!_User_name) {
        _User_name           = [[UILabel alloc] init];
        _User_name.font      = [UIFont systemFontOfSize:14];
        _User_name.textColor = NewsinfoColor;
        _User_name.frame = CGRectMake(65, 15, RECRWITCH/2-20, 40);
        _User_name.text=@"司徒久";
    }
    return _User_name;
}

-(UILabel *)Label_showtype{
    if (!_Label_showtype) {
        _Label_showtype           = [[UILabel alloc] init];
        _Label_showtype.font      = [UIFont boldSystemFontOfSize:20];
        _Label_showtype.textColor = LineColor;
        _Label_showtype.textAlignment=NSTextAlignmentRight;
    }
    return _Label_showtype;
}

-(UILabel *)Label_bottom{
    if (!_Label_bottom) {
        _Label_bottom           = [[UILabel alloc] init];
        _Label_bottom.font      = [UIFont systemFontOfSize:16];
        _Label_bottom.textColor = NewsinfoColor;
        _Label_bottom.numberOfLines = 0;
        _Label_bottom.frame = CGRectMake(15, 65, RECRWITCH-30, 40);
        _Label_bottom.text=@"科技 9 点见：传三星代工高通5G芯片大量报废 拼多多发布Q2财报";
    }
    return _Label_bottom;
}

-(UILabel *)Label_count{
    if (!_Label_count) {
        _Label_count           = [[UILabel alloc] init];
        _Label_count.font      = [UIFont systemFontOfSize:14];
        _Label_count.textColor = NewsotherColor;
        _Label_count.frame = CGRectMake(15, 105, RECRWITCH-30, 30);
        _Label_count.text=@"190赞        10分钟前";
    }
    return _Label_count;
}

- (CALayer *)News_line{
    if (!_News_line) {
        _News_line = [[CALayer alloc] init];
        _News_line.frame=CGRectMake(0, 145, RECRWITCH, 1);
        _News_line.backgroundColor=LineColor.CGColor;
    }
    return _News_line;
}

- (UIButton *)Morebutton{
    if (!_Morebutton) {
        _Morebutton = [[UIButton alloc] initWithFrame:CGRectMake(RECRWITCH-40, 15, 20, 40)];
        [_Morebutton setImage:[UIImage imageNamed:@"news_more"] forState:UIControlStateNormal];
        _Morebutton.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_Morebutton addTarget:self action:@selector(moreshow:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _Morebutton;
}

- (void)moreshow:(UIButton *)sender{
    
//    __weak __typeof(&*self)weakSelf = self;
    UserJubuViewModel *actionjubao = [UserJubuViewModel show:_supervsl dic:@{@"userid":@"0",@"type":@"0",@"to_userid":@"0",@"to_id":@"10"}];
    actionjubao.selectblock = ^(BOOL type) {
//        [weakSelf cunJubao];
    };
    
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//
//    NSString *show_title;
//    if ([[UserModel info].userid isEqualToString:_Model.userid]) {
//        show_title = @"删除";
//    }else{
//        show_title = @"回复";
//    }
//
//    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:show_title style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
//        if ([[UserModel info].userid isEqualToString:_Model.userid]) {
//            [self deletecomm];
//        }else{
//            self->_seleckblock(1);
//        }
//    }];
//    [alertController addAction:sureAction];
//
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//    [alertController addAction:cancelAction];
//
//    [_SuperVC presentViewController:alertController animated:YES completion:nil];
    
}

- (void)gotousercenter:(UIButton *)sender{
    
    UserModel *linmodel = [UserModel new];
    linmodel.userid = _Model.userid;
    linmodel.name = _Model.name;
    linmodel.logo = _Model.logo;
    linmodel.briday = _Model.briday;
    linmodel.sex = _Model.sex;
    
    [CenterAction Actiontodone:JonesGOTO_User_Center view:_supervsl dictionary:@{@"model":linmodel}];
}

@end
